package com.xinke.edu.mypetadoption.fragment2.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter4.BaseQuickAdapter;
import com.chad.library.adapter4.viewholder.QuickViewHolder;
import com.xinke.edu.mypetadoption.R;
import com.xinke.edu.mypetadoption.entity.OrdersUserProductDTO;

public class DdAdpter extends BaseQuickAdapter<OrdersUserProductDTO, QuickViewHolder> {

    @Override
    protected void onBindViewHolder(@NonNull QuickViewHolder quickViewHolder, int i, @Nullable OrdersUserProductDTO order) {
        ImageView img = quickViewHolder.getView(R.id.ddtp);
        Glide.with(getContext()).load(order.getCoverImage()).into(img);

        quickViewHolder.setText(R.id.ddmc,order.getProductName());

        quickViewHolder.setText(R.id.ddbh,order.getOrderNo());

        // 状态（int → String）
        String statusText = getStatusText(order.getStatus());
        quickViewHolder.setText(R.id.ddzt, statusText);

        // 数量（int → String）
        quickViewHolder.setText(R.id.ddsl, String.valueOf(order.getQuantity()));

        // 商品价格（double → String）
        quickViewHolder.setText(R.id.ddjg, String.valueOf(order.getProductPrice()));

        quickViewHolder.setText(R.id.mjxm, order.getUsername());

        quickViewHolder.setText(R.id.dddz,order.getMerchantAddress());

        quickViewHolder.setText(R.id.dddh,order.getUserPhone());

        // 总价（double → String）
        quickViewHolder.setText(R.id.ddzj, String.valueOf(order.getTotalAmount()));

        quickViewHolder.setText(R.id.ddsj,"               "+order.getPaymentTime());
    }

    /**
     * 根据订单状态码获取对应的文字描述
     * @param status 状态码：0-待付款，1-待发货，2-已发货，3-已完成，4-已取消
     * @return 状态文字描述
     */
    private String getStatusText(int status) {
        switch (status) {
            case 0:
                return "待付款";
            case 1:
                return "待发货";
            case 2:
                return "已发货";
            case 3:
                return "已完成";
            case 4:
                return "已取消";
            default:
                return "未知状态";
        }
    }

    @NonNull
    @Override
    protected QuickViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new QuickViewHolder(R.layout.item_sj_dd,viewGroup);
    }
}
